package com.anli.Service.impl;

import com.anli.Mapper.EmpMapper;
import com.anli.Service.EmptService;
import com.anli.pojo.Emp;
import com.anli.pojo.pageBean;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.autoconfigure.PageHelperProperties;
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class EmptServiceImpl implements EmptService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private PageHelperProperties pageHelperProperties;
    private Gson gson ;
    @Override
    public pageBean page(Integer page,Integer pageSize,String name, Short gender, LocalDateTime begin, LocalDateTime end) {
//        Long count = empMapper.count();
//        Integer start = (page-1)*pageSize;
//        List<Emp> empList = empMapper.page(start, pageSize);
        PageHelper.startPage(page,pageSize);
        List<Emp> list = empMapper.list(name,gender,begin,end);
        Page<Emp> p = (Page<Emp>) list;
        pageBean pageBean = new pageBean(p.getTotal(), p.getResult());

        return pageBean;
    }

    @Override
    public void delete(List<Integer> ids) {
        empMapper.delete(ids);
    }

    @Override
    public void save(Emp emp) {
        emp.setCreateTime(LocalDateTime.now());
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.insert(emp);
    }

    @Override
    public Emp getById(Integer id) {
        return empMapper.getById(id);
    }

    @Override
    public void update(Emp emp) {
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.update(emp);
    }

    @Override
    public Emp login(Emp emp) {
        return empMapper.getByUserNameAndByPassWord(emp);
    }
}
